//
//  MHInformationTableViewCell.m
//  ManHua
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHInformationTableViewCell.h"

#import <UIButton+WebCache.h>
#import "NSString+Additional.h"
#import "UILabel+Additional.h"
@interface MHInformationTableViewCell()
@property(nonatomic,strong)UILabel *titleButton;//标题图片
@property(nonatomic,strong)UILabel *titleName;//标题名字
@property(nonatomic,strong)UIButton *moreBookButton;
@property(nonatomic,strong)UIView *lineView;//分割线视图
@property(nonatomic,strong)UIButton *bookButton;
@property(nonatomic,strong)UILabel *bookName;
@property(nonatomic,strong)UIButton *secondBoolButton;
@property(nonatomic,strong)UILabel *secondBookName;
@property(nonatomic,assign)CGFloat cellOfHeight;
@property(nonatomic,strong)MHTopicBannerModel *BookIDModel;
//@pr
@end

@implementation MHInformationTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
     
          self.selectionStyle = UITableViewCellSelectionStyleNone;
      
            _titleButton=[[UILabel alloc]init];
            _titleButton.frame=CGRectMake(10, 10, 20, 20);
            [_titleButton.layer setCornerRadius:10];
            CGRect rect1=_titleButton.frame;
        _titleButton.text = @"✨";
        _titleButton.textColor = KThemPinkColor;
        _titleButton.font = [UIFont systemFontOfSize:15];
        
            [self.contentView addSubview:_titleButton];
            
            _titleName=[[UILabel alloc]initWithFrame:CGRectMake(rect1.origin.x+rect1.size.width, rect1.origin.y,Width/3 , 30)];
        _titleName.font=[UIFont fontWithName:@"Courier-Bold" size:14];
        _titleName.textColor=KThemPinkColor;
            CGRect rect2=_titleName.frame;
            [self.contentView addSubview:_titleName];
        self.moreBookButton=[UIButton buttonWithType:UIButtonTypeSystem];
        [self.moreBookButton setImage:[[UIImage imageNamed:@""@"iconfont-iconfontgengduo"] imageWithRenderingMode:  UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
     
        [self.moreBookButton addTarget:self action:@selector(skipTomoreBookPage:) forControlEvents:UIControlEventTouchUpInside];
        self.moreBookButton.frame=CGRectMake(Width-40, rect1.origin.y, 30, rect1.origin.y+rect1.size.height);
        [self.contentView addSubview:_moreBookButton];
        self.lineView=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(rect2), Width, 0.5)];
        self.lineView.backgroundColor=[UIColor lightGrayColor];
        CGRect lineViewFrame=self.lineView.frame;
        [self.contentView addSubview:_lineView];
        CGFloat bookButtonW = Width / 2 - 15;
        CGFloat bookButtonH = 640.0 / 1024.0 * bookButtonW;
        self.bookButton =[[UIButton alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(lineViewFrame)+10, bookButtonW, bookButtonH)];
            [self.contentView addSubview:_bookButton];
        [self.bookButton addTarget:self action:@selector(SkipTomoreBookCVC:) forControlEvents:UIControlEventTouchUpInside];
        self.bookButton.tag=1001;
        
        self.secondBoolButton=[[UIButton alloc]initWithFrame:CGRectMake(Width/2+5, CGRectGetMaxY(lineViewFrame)+10, Width/2-15, bookButtonH)];
        self.secondBoolButton.tag=1002;
        [self.secondBoolButton addTarget:self action:@selector(SkipTomoreBookCVC:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_secondBoolButton];
        self.bookName=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.secondBoolButton.frame)+5, Width/2-15, 20)];
        self.bookName.font=[UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.bookName];
        self.secondBookName=[[UILabel alloc]initWithFrame:CGRectMake(Width/2+5, CGRectGetMaxY(self.secondBoolButton.frame)+5, Width/2-15, 20)];
        self.secondBookName.font =[UIFont systemFontOfSize:12];
        [self.contentView addSubview:_secondBookName];
            self.cellOfHeight=CGRectGetMaxY(self.secondBookName.frame)+10;
        

    }
        return self;
}


-(void)skipTomoreBookPage:(UIButton *)button
{
    if (self.showCVCBlock!=nil) {
        self.showCVCBlock(self.topicTopicModel);
    }
}



-(void)setTopicTopicModel:(MHMainTopicModel *)topicTopicModel
{
    _topicTopicModel=topicTopicModel;
    _titleName.text=topicTopicModel.Title;
    CGFloat width = [NSString textFrameWithFont:_titleName.font String:topicTopicModel.Title maxSize:CGSizeMake(0, _titleName.frame.size.height)].width;
    _titleName.frame=CGRectMake(_titleName.frame.origin.x, _titleName.frame.origin.y, width,_titleName.frame.size.height);
}
-(void)setDataSourceArr:(NSMutableArray *)dataSourceArr
{
    _dataSourceArr=dataSourceArr;
    [dataSourceArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        MHTopicBannerModel *bannerModel=(MHTopicBannerModel *)obj;
        if (idx==0) {
            [self.bookButton sd_setImageWithURL:[NSURL URLWithString:bannerModel.TopicIconUrl] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"f3c2d7039245d688094612bba6c27d1ed21b242c.jpg"]];
            
            self.bookName.text=bannerModel.TopicName;
        }
        else if (idx==1)
        {
            [self.secondBoolButton sd_setImageWithURL:[NSURL URLWithString:bannerModel.TopicIconUrl] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"f3c2d7039245d688094612bba6c27d1ed21b242c.jpg"]];
            
            self.secondBookName.text=bannerModel.TopicName;
        }
    }];
}

-(void)SkipTomoreBookCVC:(UIButton*)button
{NSInteger tagNum=button.tag-1000;
    if (tagNum==1) {
        self.BookIDModel=(MHTopicBannerModel *)self.dataSourceArr[0];
    }
    else if (tagNum==2)
    {
     self.BookIDModel=(MHTopicBannerModel *)self.dataSourceArr[1];
    }
    if (self.moreBookCVCBlock!=nil) {
        self.moreBookCVCBlock(self.BookIDModel,_titleName.text);
    }
}
-(CGFloat)heightCell
{
    return _cellOfHeight;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
